package com.wc.alorithm_luogu._国赛模拟赛.I_数据结构;

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/5/19 11:41
 * @description https://www.luogu.com.cn/problem/T439264?contestId=170180
 */
public class Main {
    static Scanner sc = new Scanner(System.in);
//    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static long[] maxA = new long[N << 2], minA = new long[N << 2];
    static long[] maxB = new long[N << 2], minB = new long[N << 2];
    static long[] sum = new long[N << 2];
    static long[] add = new long[N << 2];
    static int[] A = new int[N];
    static int[] B = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) A[i] = sc.nextInt();
        for (int i = 1; i <= n; i++) B[i] = sc.nextInt();
        build(1, 1, n);
        int op, l, r, k, t, i, x, y;
        while (m-- > 0) {
            op = sc.nextInt();
            if (op == 1) {
                l = sc.nextInt();
                r = sc.nextInt();
                k = sc.nextInt();
                t = sc.nextInt();
                if (t == 0) continue;
                modify1(1, 1, n, l, r, k, t);
            } else if (op == 2) {
                i = sc.nextInt();
                x = sc.nextInt();
                y = sc.nextInt();
                modify2(1, 1, n, i, x, y);
            } else {
                l = sc.nextInt();
                r = sc.nextInt();
                out.println(query(1, 1, n, l, r));
            }
        }
        out.flush();
    }

    static void build(int u, int l, int r) {
        if (l == r) {
            maxA[u] = minA[u] = A[l];
            maxB[u] = minB[u] = B[l];
            sum[u] = A[l] + B[l];
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushUp(u);
    }

    static void pushUp(int u) {
        sum[u] = sum[u << 1] + sum[u << 1 | 1];
        maxA[u] = Math.max(maxA[u << 1], maxA[u << 1 | 1]);
        minA[u] = Math.min(minA[u << 1], minA[u << 1 | 1]);
        maxB[u] = Math.max(maxB[u << 1], maxB[u << 1 | 1]);
        minB[u] = Math.min(minB[u << 1], minB[u << 1 | 1]);
    }

    static void modify1(int u, int l, int r, int ql, int qr, int k, int t) {
        if (minA[u] * minB[u] > k) return;
        if (l == ql && r == qr && maxA[u] * maxB[u] <= k) {
            pushDown(u, l, r, t);
            return;
        }
        pushDown(u, l, r);
        int mid = l + r >> 1;
        if (qr <= mid) modify1(u << 1, l, mid, ql, qr, k, t);
        else if (ql > mid) modify1(u << 1 | 1, mid + 1, r, ql, qr, k, t);
        else {
            modify1(u << 1, l, mid, ql, mid, k, t);
            modify1(u << 1 | 1, mid + 1, r, mid + 1, qr, k, t);
        }
        pushUp(u);
    }

    static void modify2(int u, int l, int r, int i, int x, int y) {
        if (l == r) {
            maxA[u] = minA[u] = x;
            maxB[u] = minB[u] = y;
            sum[u] = x + y;
            return;
        }
        pushDown(u, l, r);
        int mid = l + r >> 1;
        if (i <= mid) modify2(u << 1, l, mid, i, x, y);
        else modify2(u << 1 | 1, mid + 1, r, i, x, y);
        pushUp(u);
    }

    static long query(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) {
            return sum[u];
        }
        pushDown(u, l, r);
        int mid = l + r >> 1;
        if (qr <= mid) return query(u << 1, l, mid, ql, qr);
        else if (ql > mid) return query(u << 1 | 1, mid + 1, r, ql, qr);
        return query(u << 1, l, mid, ql, mid) + query(u << 1 | 1, mid + 1, r, mid + 1, qr);
    }

    static void pushDown(int u, int l, int r) {
        if (add[u] > 0) {
            int mid = l + r >> 1;
            pushDown(u << 1, l, mid, add[u]);
            pushDown(u << 1 | 1, mid + 1, r, add[u]);
            add[u] = 0;
        }
    }

    static void pushDown(int u, int l, int r, long t) {
        sum[u] = sum[u] + 2L * (r - l + 1) * t;
        maxA[u] += t;
        minA[u] += t;
        maxB[u] += t;
        minB[u] += t;
        add[u] += t;
    }
}
//
//class FastReader {
//    StringTokenizer st;
//    BufferedReader br;
//
//    FastReader() {
//        br = new BufferedReader(new InputStreamReader(System.in));
//    }
//
//    String next() {
//        while (st == null || !st.hasMoreElements()) {
//            try {
//                st = new StringTokenizer(br.readLine());
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        return st.nextToken();
//    }
//
//    int nextInt() {
//        return Integer.parseInt(next());
//    }
//
//    String nextLine() {
//        String s = "";
//        try {
//            s = br.readLine();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return s;
//    }
//
//    long nextLong() {
//        return Long.parseLong(next());
//    }
//
//    double nextDouble() {
//        return Double.parseDouble(next());
//    }
//
//    // 是否由下一个
//    boolean hasNext() {
//        while (st == null || !st.hasMoreTokens()) {
//            try {
//                String line = br.readLine();
//                if (line == null)
//                    return false;
//                st = new StringTokenizer(line);
//            } catch (IOException e) {
//                throw new RuntimeException(e);
//            }
//        }
//        return true;
//    }
//}